import sys
from PySide6 import QtCore, QtWidgets
import ui_dlgStandards
from PySide6.QtCore import Slot
from PySide6 import QtSql
import ui_dlgOpenSample
import myglobal
class doubleDelegate(QtWidgets.QItemDelegate):
    def createEditor(self,parent, option,index):
        editor =QtWidgets.QLineEdit(parent)
        return editor;
    def setEditorData(self,editor, index):
        value = index.model().data(index)
        editor.setText(str(value))
    def setModelData(self,editor,model,index):
        value = editor.text()
        model.setData(index, value)
    def updateEditorGeometry(self,editor,option,index):
        editor.setGeometry(option.rect)
class DlgTableEdit(QtWidgets.QDialog):
    ui=ui_dlgOpenSample.Ui_Dialog();
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        self.ui.setupUi(self)
        self.model = QtSql.QSqlRelationalTableModel(self);
        self.model.setTable("standard");
        self.model.select();
        self.ui.tableView.setModel(self.model);
        self.ui.tableView.setSortingEnabled(True);
        m_cBoxDelegate=doubleDelegate()
        self.ui.tableView.setItemDelegateForColumn(2, m_cBoxDelegate);
        self.ui.tableView.setItemDelegateForColumn(3, m_cBoxDelegate);
    def add_click(self):
        # myglobal.db.
        self.model.insertRow(0)
        pass
    def delete_click(self):
        current=self.ui.tableView.currentIndex();
        row=current.row();
        self.model.removeRow(row)
        pass

    def month_change(self):
        pass
    def day_change(self):
        pass
    def name_begin_change(self):
        pass
    def name_end_change(self):
        pass
    def name_include_change(self):
        pass
    def name_equal_change(self):
        pass
    def use_date(self):
        pass
    def use_name(self):
        pass
    def query(self):
        pass
    def selectall(self):
        pass
   # self.spinBox_month.valueChanged.connect(Dialog.month_change)
   #      self.spinBox_day.valueChanged.connect(Dialog.day_change)
   #      self.lineEdit_begin.textChanged.connect(Dialog.name_begin_change)
   #      self.lineEdit_end.textChanged.connect(Dialog.name_end_change)
   #      self.lineEdit_include.textChanged.connect(Dialog.name_include_change)
   #      self.lineEdit_equal.textChanged.connect(Dialog.name_equal_change)
   #      self.checkBox_date.clicked.connect(Dialog.use_date)
   #      self.checkBox_name.clicked.connect(Dialog.use_name)
   #      self.pushButton_query.clicked.connect(Dialog.query)
   #      self.pushButton_selectall.clicked.connect(Dialog.selectall)
    @Slot()
    def accept(self):
        self.model.submitAll();
        self.done(0)
    @Slot()    
    def reject(self):
        self.done(0)
if __name__ == "__main__":
    from PySide6 import QtCore, QtWidgets
    import sys
    a = QtWidgets.QApplication(sys.argv)
    a.lastWindowClosed.connect(a.quit)
    w =dlgstandard()
    w.show()
    sys.exit(a.exec_())